(function ($) {
    $.dataCenter = function () {
        return {	//书本基本信息
            subjectList: {},
            pageSize: 10,
            pageIndex: 0,
            bookStatus: 0,
            pageParam: {},
            schoolList:[],//学校列表
            alterAuthIdList:[],//修改资源auth idList
            init: function () {
                this.listener();
                this.initLayui();
                this.periodInfoGet();
                this.getUserInfo();
                this.tableTab();
                this.dataList();
            },
            /**
             * 添加各按钮所需要的监听事件
             */
            listener: function () {
                /**
                 *校本 公开的科目选择
                 * **/
                $(".publicSubjectSel").on("click", "li", function () {
                    $(this).siblings().removeClass("active");
                    $(this).addClass("active");
                    $.dataCenter.dataList();
                });
                /**
                 *点击个人 校本 公开
                 * **/
                $(".authType li").on("click", function () {
                    var auth = $(this).attr("data-auth");
                    $(".authType").attr("data-auth", auth);
                    //将之前选择的重新定义
                    $(".subjectSel").val("0");
                    $("#searchInput").val("");
                    $(".publicSubjectSel li,#dataCenterLeft li").removeClass("active");
                    $(".publicSubjectSel li:first-child,#dataCenterLeft li:first-child").addClass("active");
                    $.dataCenter.tableTab();
                    $.dataCenter.dataList();
                //    变化table高度
                    $.dataCenter.resize();
                });
                /**
                 *点击图片预览 课件预览
                 * **/
                $("#dataCenterRight").on("click", ".iconMedia,.names", function () {
                    var extensionArr = $(this).data("fileurl").split(".");
                    var extension = extensionArr[extensionArr.length - 1];
                    if (extension != "cwep") {
                        //页面层
                        // layer.open({
                        //     type: 2,
                        //     title: '备课资料',
                        //     shadeClose: true, //开启遮罩关闭
                        //     area: ['1024px', window.innerHeight - 100 + "px"], //宽高
                        //     content: SystemConfig.openPlayView+ $(this).data("fileurl")
                        // });
                        window.open(SystemConfig.openPlayView+ $(this).data("fileurl"))
                    }
                });
                /**
                 *监听设置科目
                 * **/
                $("#subjectType").on("change", function () {
                    console.log($(this).find("option:selected").attr("data-id"))
                    // $.dataCenter.alterSubject()
                });
                /**
                 *点击侧边栏选择文件类型
                 * **/
                $("#dataCenterLeft").on("click", "li", function () {
                    $(this).siblings(".active").removeClass("active");
                    $(this).addClass("active");
                    $.dataCenter.dataList();
                });

                /**
                 *点击排序
                 * **/
                $(".dataCenterList").on("click", ".sort", function () {
                    if ($(this).attr("data-isasc") == "2") {
                        $(this).attr("data-isasc", "1");
                        $(this).find(".icon").css("background-image", "url('imgs/ltb.png')");
                    } else {
                        $(this).attr("data-isasc", "2");
                        $(this).find(".icon").css("background-image", "url('imgs/btl.png')");
                    }
                    $.dataCenter.dataList();
                });
                /**
                 *页面调整
                 * **/
                $.dataCenter.resize();
                $(window).resize($.dataCenter.resize);
                $("#searchInput").keydown(function () {
                    if (event.keyCode == 13) {
                        $.dataCenter.dataList();
                    }
                });
                $("#personSearchBtn").click(function () {
                    $.dataCenter.dataList();
                });
                /**
                 * 点击转存
                 */
                $(".dataCenterList").on("click", ".save", function () {
                    var resourceDump = {
                        "idList": [$(this).parents("tr").attr("data-id")],
                        "token": User.token
                    };
                    $.dataCenter.resourceDump(resourceDump);
                });
                /**
                 * 点击批量转存
                 */
                $(".saveSel").on("click", function () {
                    var inputs = $(".dataCenterList").find("tbody input[type='checkbox']:checked");
                    var idList = [];
                    if (inputs.length > 0) {
                        $.each(inputs, function (i, inputDom) {
                            idList.push($(inputDom).parents("tr").data('id'));
                        });
                        var resourceDump = {
                            "idList": idList,
                            "token": User.token
                        };
                        $.dataCenter.resourceDump(resourceDump);
                    } else {
                        layer.msg("请点击选中项再转存");
                    }
                });

                /**
                 * 监听hover事件
                 */
                $(".dataCenterList").on("mouseover mouseout", "tbody tr", function (event) {
                    if (event.type == "mouseover") {
                        //鼠标悬浮
                        $(this).find(".controlButtons").css("display", "inline-block");
                    } else if (event.type == "mouseout") {
                        //鼠标离开
                        $(this).find(".controlButtons").css("display", "none");
                    }
                });
                /**
                 * 点击确定修改
                 */
                $(".dataCenterList").on("click", ".dataNameEdit .icon.confirm", function () {
                    $.dataCenter.inputEdit($(this).prev().find("input"));
                });
                /**
                 * 监听input变化
                 */
                $(".dataCenterList").on("blur", "input.editNameInput", function () {
                    var other = $(this).parents("tr");
                    setTimeout(function () {
                        other.find(".dataNameEdit").css("display", "none");
                        other.find(".names").css("display", "inline-block");
                    }, 500);
                    $(this).parents(".dataCenterList").on("mouseover", "tbody tr", function () {
                        $(this).find(".controlButtons").css("display", "inline-block");
                    });
                });
                $(".dataCenterList").on("keydown", "input.editNameInput", function () {
                    if (event.keyCode == 13) {
                        $(this).parents("tr").find(".dataNameEdit").css("display", "none");
                        $(this).parents(".dataCenterList").on("mouseover", "tbody tr", function () {
                            $(this).find(".controlButtons").css("display", "inline-block");
                        });
                        $.dataCenter.inputEdit($(this));
                    }
                });
                /**
                 * 点击编辑资料名称
                 */
                $(".dataCenterList tbody").on('click', ".editor", function () {
                    $(this).parent().css("display", "none");
                    $(this).parents(".dataCenterList").off("mouseover");
                    // $(this).parents("tr").find(":hover .controlButtons").css("display", "none");
                    $(this).parent().prev().css("display", "none");
                    $(this).parents("tr").find(".dataNameEdit").css("display", "inline-block");
                    $(this).parents("tr").find(".dataNameEdit input").val($(this).parent().prev().find(".name").html()).focus();
                });
                /**
                 * 删除一行
                 */
                $(".dataCenterList tbody").on('click', ".delete", function () {
                    var resourceDelete = {
                        "idList": [$(this).parents("tr").data("id")],
                        "token": User.token
                    };
                    resourceDelete = JSON.stringify(resourceDelete);
                    $.dataCenter.deleteFile(resourceDelete, Doman.resourceDelete);
                });
                /**
                 * 删除选中行
                 */
                $(".deleteSel").on('click', function () {
                    var inputs = $(".dataCenterList").find("tbody input[type='checkbox']:checked");
                    var idList = [];
                    if (inputs.length > 0) {
                        $.each(inputs, function (i, inputDom) {
                            idList.push($(inputDom).parents("tr").data('id'));
                        });
                        var topicDelete = {
                            "idList": idList,
                            "token": User.token
                        };
                        topicDelete = JSON.stringify(topicDelete);
                        $.dataCenter.deleteFile(topicDelete, Doman.resourceDelete);
                    } else {
                        layer.msg("请点击选中项再删除");
                    }
                });
                /**
                 * 下载单行
                 */
                $(".dataCenterList tbody").on('click', ".download", function () {
                    var extension = $(this).parents("tr").data('extension').toUpperCase();
                    if (extension == "JPG" || extension == "JPEG" || extension == "PNG" || extension == "MP3" || extension == "MP4") {
                        urls = [{"url": $(this).parents("tr").data('fileurl')}];
                        $.dataCenter.downloadZip(urls);
                    } else {
                        window.location = $(this).parents("tr").data('fileurl');
                    }
                });
                /**
                 * 下载选中行
                 */
                $(".downloadSel").on('click', function () {
                    var inputs = $(".dataCenterList").find("tbody input[type='checkbox']:checked");
                    var urls = [];
                    if (inputs.length > 1) {
                        $.each(inputs, function (i, inputDom) {
                            urls.push({"url": $(inputDom).parents("tr").data('fileurl')});
                        });
                        $.dataCenter.downloadZip(urls);
                    } else if (inputs.length == 1) {
                        var extension = $(inputs).parents("tr").data('extension').toUpperCase();
                        if (extension == "JPG" || extension == "JPEG" || extension == "PNG" || extension == "MP3" || extension == "MP4") {
                            urls = [{"url": $(inputs).parents("tr").data('fileurl')}];
                            $.dataCenter.downloadZip(urls);
                        } else {
                            window.location = $(inputs).parents("tr").data('fileurl');
                        }
                    } else {
                        layer.msg("请点击选中项再下载");
                    }
                    $.dataCenter.inputEmpty();
                });

                /**
                 * 点击上传资料
                 */
                $(".uploadData").on('click', function () {
                    var height = window.innerHeight - 200 + "px";
                    //iframe窗
                    layer.open({
                        type: 2,
                        title: "上传资料",
                        area: ['900px', height],
                        content: "pageFrame/uploadData.html"
                        , btn: ['确定上传']
                        , yes: function (index, layero) {
                            var uploadFileList = layer.getChildFrame(".preUplad li", index);
                            var dtoList = [];
                            $.each(uploadFileList, function (i, li) {
                                if ($(li).find(".fileContril").html() == "上传成功") {
                                    var obj = {};
                                    obj.extension = $(li).data("filenamesuffix");
                                    obj.fileLength = $(li).data("filesize");
                                    obj.fileUrl = $(li).attr("fileurl");
                                    if ($(li).find(".remark").val() == "") {
                                        obj.name = $(li).data("filename");
                                    } else {
                                        obj.name = $(li).find(".remark").val();
                                    }
                                    dtoList.push(obj);
                                }
                            });
                            var resourceSaveData = {
                                "dtoList": dtoList,
                                "token": User.token
                            };
                            saveObject(Doman.dataCenterUrl + Doman.resourceSave, true, JSON.stringify(resourceSaveData), function (result) {
                                if (result.code == 200) {
                                    layer.msg(result.message, {icon: 1});
                                } else {
                                    layer.msg(result.message, {icon: 2});
                                }
                                $("#subject").val("");
                                $("#fileType").val("");
                                $("#searchInput").val("");
                                $.dataCenter.pageIndex = 0;
                                $.dataCenter.dataList();
                                layer.close(index);
                            }, function () {
                                layer.msg("保存失败，请稍后重试", {icon: 2});
                            });
                        }
                    });
                });
                /**
                 * 点击设置权限
                 */
                $(".alterAuth").on('click', function () {
                    var inputs = $(".dataCenterList").find("tbody input[type='checkbox']:checked");
                    var idList = [];
                    if (inputs.length > 0) {
                        if(inputs.length=="1"){//如果选中资源唯一 则有学校列表
                            $.dataCenter.schoolList=JSON.parse($(inputs).prev().html())
                        }
                        $.each(inputs, function (i, inputDom) {
                            idList.push($(inputDom).parents("tr").data('id'));
                        });
                        $.dataCenter.alterAuthIdList=idList;
                        var height = window.innerHeight - 200 + "px";
                        //iframe窗
                        layer.open({
                            type: 2,
                            title: "设置权限",
                            area: ['900px', height],
                            content: "pageFrame/alterAuth.html"
                            , btn: ['确定']
                            , yes: function (index, layero) {
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                                if(body.find(".newSchool").css("display")=="block"){//如果学校确定选中
                                    iframeWin.$.alterAuth.addSchool();//调用子页面的方法，得到子页面返回的ids
                                }else{//如果保存修改权限
                                    iframeWin.$.alterAuth.alter();
                                    layer.close(index);
                                    $.dataCenter.dataList(true);
                                    $.dataCenter.schoolList=[];
                                }
                            }
                            ,cancel:function(index, layero){
                                $.dataCenter.inputEmpty();
                                layer.close(index);
                            }
                        });
                    } else {
                        layer.msg("请点击选中项再设置权限");
                    }
                });
            },
            /**
             * 页面设置高度
             * **/
            resize: function () {
                $("#dataCenterLeft,#dataCenterRight").css("height", window.innerHeight - 50 + "px");
                if($(".authType").attr("data-auth")=="1"){
                    $(".table").css("height", window.innerHeight - 180 + "px");
                }else{
                    $(".table").css("height", window.innerHeight - 204 + "px");
                }
            },
            /**
             * 下载zip
             * **/
            downloadZip: function (urls) {
                var index = layer.load(1);
                var batchDownload = {
                    "urls": urls
                };
                updateObject(Doman.dataCenterUrl + Doman.batchDownload, true, JSON.stringify(batchDownload), function (result) {
                    if (result.code == 200) {
                        window.location = result.url;
                    }
                    layer.close(index);
                }, function () {
                });
            },
            /**
             * input修改数据
             * data 数据
             * **/
            inputEdit: function (othis) {
                othis.parents("tr").find(".dataName").css("display", "inline-block");
                othis.parents("tr").find(".dataName").next().css("display", "inline-block");
                if ($.trim(othis.val()) != "") {
                    othis.parents("tr").find(".dataName").html(othis.val());
                    var alterInfo = {
                        "id": othis.parents("tr").data("id"),
                        "name": othis.val(),
                        "token": User.token
                    };
                    $.dataCenter.alterInfo(alterInfo);
                    $.dataCenter.dataList(true);
                } else {
                    layer.msg("资料名称不可为空", {icon: 2});
                }
            },
            /**
             * 删除确认弹出框
             * data 数据
             * url 地址
             * **/
            deleteFile: function (data, url) {
                layer.confirm('是否删除', {
                    btn: ['确定', '取消'] //按钮
                }, function (index, layero) {
                    delObject(Doman.dataCenterUrl + url, true, data, function (result) {
                        $.dataCenter.dataList(true);
                        layer.close(index);
                    });
                }, function () {
                });
            },
            /**
             * 资源转存
             * data 数据
             * **/
            resourceDump:function(resourceDump){
                updateObject(Doman.dataCenterUrl + Doman.resourceDump, false, JSON.stringify(resourceDump), function (result) {
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1});
                    } else {
                        layer.msg(result.message, {icon: 2});
                    }
                }, function (result) {
                    layer.msg(JSON.parse(result.responseText).message, {icon: 2});
                });
                $.dataCenter.dataList();
            },
            initLayui: function () {
                layui.use(['layer', 'form', 'element', 'laypage', 'table'], function () {
                    $ = layui.jquery, layer =(parent.layer === undefined) ? layui.layer : parent.layer, element = layui.element, form = layui.form,
                        table = layui.table, laypage = layui.laypage;
                    form.render('checkbox');
                    form.render('select');
                    //全选
                    form.on('checkbox(allChoose)', function (data) {
                        var child = $(this).parents(".dataCenterList").find('tbody input[type="checkbox"]');
                        child.each(function (index, item) {
                            item.checked = data.elem.checked;
                        });
                        form.render('checkbox');
                    });
                    //监听科目删选
                    form.on('select(subjectType)', function (data) {
                        $.dataCenter.dataList();
                    });
                    //监听科目设置
                    form.on('select(subjectTypeSet)', function (data) {
                        var subjectId = $(data.elem).find("option:checked").attr("data-id");
                        var inputs = $(".dataCenterList").find("tbody input[type='checkbox']:checked");
                        var idList = [];
                        if (inputs.length > 0) {
                            $.each(inputs, function (i, inputDom) {
                                idList.push($(inputDom).parents("tr").data('id'));
                            });
                            var resourceAlterSubject = {
                                "idList": idList,
                                "subjectId": subjectId,
                                "token": User.token
                            };
                            updateObject(Doman.dataCenterUrl + Doman.resourceAlterSubject, false, JSON.stringify(resourceAlterSubject), function (result) {
                                console.log(result)
                                if (result.code == 200) {
                                    layer.msg(result.message, {icon: 1});
                                } else {
                                    layer.msg(result.message, {icon: 2});
                                }
                            }, function (result) {
                                layer.msg(JSON.parse(result.responseText).message, {icon: 2});
                            });
                        } else {
                            layer.msg("请点击选中项再更改科目");
                        }
                        $.dataCenter.dataList(true);
                        $(".subjectSet").val("设置科目");
                        form.render('select');
                    });
                });
            },
            periodInfoGet: function () {
                var periodInfoGet={token:User.token};
                updateObject(Doman.dataCenterUrl + Doman.periodInfoGet, false, JSON.stringify(periodInfoGet), function (result) {
                    if (result.code != "200") {
                        layui.use(['layer', 'form', 'element'], function () {
                            $ = layui.jquery, layer = layui.layer, element = layui.element, form = layui.form;
                            //页面层
                            layer.open({
                                type: 2,
                                title: '请选择您的教学课程范围',
                                closeBtn: 0,
                                shadeClose: false, //开启遮罩关闭
                                area: ['1024px', window.innerHeight - 100 + "px"], //宽高
                                content: "pageFrame/periodInfoSet.html"
                            });
                        });
                    }
                }, function () {
                });
            },
            alterInfo: function (data) {
                updateObject(Doman.dataCenterUrl + Doman.alterInfo, false, JSON.stringify(data), function (result) {
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1});
                    } else {
                        layer.msg(result.message, {icon: 2});
                    }
                }, function () {
                });
            },
            getUserInfo: function () {
                getObject(Doman.dataCenterUrl + Doman.getUserInfo + "/" + User.token, false, {}, function (data) {
                    if (data.code == 200) {
                        $("#dataCenterLeft").append($.dataCenter.typeListHtml(data.typeList));
                        $(".subjectSet").append($.dataCenter.subjectListHtml(data.subjectList));
                        $(".publicSubjectSel").append($.dataCenter.publicSubjectHtml(data.subjectList));
                        $.dataCenter.subjectList = data.subjectList;
                        $.dataCenter.initLayui();
                    }
                });
            },
            typeListHtml: function (data) {
                var html = '';
                $.each(data, function (i, data) {
                    html += '<li data-id=' + data.id + '>' + data.name + '</li>';
                });
                return html;
            },
            subjectListHtml: function (data) {
                var html = '';
                $.each(data, function (i, data) {
                    html += '<option data-id=' + data.id + ' value=' + data.id + '>' + data.name + '</option>';
                });
                return html;
            },
            publicSubjectHtml: function (data) {
                var html = '';
                $.each(data, function (i, data) {
                    html += '<li data-id=' + data.id + '>' + data.name + '</li>';
                });
                return html;
            },
            tableTab: function () {
                var colgroupHtml = "";
                var theadHtml = "";
                var auth = $(".authType").attr("data-auth");
                if (auth == "1") {
                    colgroupHtml += '<col>'
                        + '<col width="150">'
                        + '<col width="100">'
                        + '<col width="200">'
                        + '<col width="200">';
                    theadHtml += '<tr>'
                        + '    <th><input type="checkbox" name="" title="资料名" lay-skin="primary" lay-filter="allChoose"></th>'
                        + '    <th>'
                        + '        <div class="layui-inline">'
                        + '            <div class="layui-input-inline">'
                        + '                <select name="modules" lay-filter="subjectType" class="subjectSel">'
                        + '                   <option data-id="0">科目</option>'
                        + '                 </select>'
                        + '             </div>'
                        + '          </div>'
                        + '      </th>'
                        + '     <th>大小</th>'
                        + '     <th class="sort" data-isasc="2">上传时间 <span class="icon"></span></th>'
                        + '     <th></th>'
                        + '  </tr>';
                } else if (auth == "4") {
                    colgroupHtml += '<col>'
                        + '<col width="150">'
                        + '<col width="100">'
                        + '<col width="100">'
                        + '<col width="200">';
                    theadHtml += '<tr>'
                        + '    <th><input type="checkbox" name="" title="资料名" lay-skin="primary" lay-filter="allChoose"></th>'
                        + '    <th>科目</th>'
                        + '    <th>教师</th>'
                        + '    <th>大小</th>'
                        + '    <th class="sort" data-isasc="2">上传时间 <span class="icon"></span></th>'
                        + '  </tr>';
                } else if (auth == "2") {
                    colgroupHtml += '<col>'
                        + '<col width="150">'
                        + '<col width="200">'
                        + '<col width="100">'
                        + '<col width="100">'
                        + '<col width="200">';
                    theadHtml += '<tr>'
                        + '    <th><input type="checkbox" name="" title="资料名" lay-skin="primary" lay-filter="allChoose"></th>'
                        + '    <th>科目</th>'
                        + '    <th>学校</th>'
                        + '    <th>教师</th>'
                        + '    <th>大小</th>'
                        + '    <th class="sort" data-isasc="2">上传时间 <span class="icon"></span></th>'
                        + '  </tr>';
                }
                $(".dataCenterList colgroup").html(colgroupHtml);
                $(".dataCenterList thead").html(theadHtml);
                $(".subjectSel").append($.dataCenter.subjectListHtml($.dataCenter.subjectList));
            },
            dataList: function (ifPage) {
                var auth = $(".authType").attr("data-auth");
                var subject;
                if (auth == 1) {//为个人则导航栏显示person  subjectId设置
                    $(".person").css("display", "inline-block");
                    $(".public").css("display", "none");
                    subject = $(".subjectSel").find("option:selected").attr("data-id");
                } else {//为公共或校本则导航栏显示person  subjectId设置
                    $(".person").css("display", "none");
                    $(".public").css("display", "block");
                    subject = $(".publicSubjectSel .active").attr("data-id");
                }
                if (!ifPage) {
                    $.dataCenter.pageIndex = 0;
                }
                var getPage = {
                    auth: auth,
                    content: $("#searchInput").val(),
                    isASC: $(".sort").attr("data-isasc"),
                    page: $.dataCenter.pageIndex,
                    size: $.dataCenter.pageSize,
                    sortBy: 2,
                    subject: parseInt(subject),
                    token: User.token,
                    type: $("#dataCenterLeft .active").attr("data-id")
                };
                updateObject(Doman.dataCenterUrl + Doman.getPage, false, JSON.stringify(getPage), function (result) {
                    //设置个人页共多少数据
                    $(".totalNum span").html(result.totalElements);
                    var html = "";
                    if (result.content.length > 0) {
                        $.each(result.content, function (i, data) {
                            var index = $.dataCenter.pageIndex * $.dataCenter.pageSize + (i + 1);
                            var iconName = $.dataCenter.iconName(data.extension);
                            if (getPage.auth == "1") {//如果是个人
                                html += '<tr data-id=' + data.id + ' data-fileurl=' + data.fileUrl + ' data-extension=' + data.extension + '>'
                                    + '<td>'
                                    + '    <div class="schoolList">'+JSON.stringify(data.schoolList)+'</div>'
                                    + '    <input type="checkbox" name="" lay-skin="primary" title=' + index + '>'
                                    + '    <span class="iconMedia ' + iconName + '" data-fileurl=' + data.fileUrl + '></span>'
                                    + '    <div class="names" data-fileurl=' + data.fileUrl + '>'
                                    + '        <span class="name">' + data.name + '</span>.<span class="extension">' + data.extension + '</span>'
                                    + '    </div>'
                                    + '    <div class="controlButtons">'
                                    + '        <span class="icon editor"></span>'
                                    + '        <span class="icon download"></span>'
                                    + '        <span class="icon delete"></span>'
                                    + '     </div>'
                                    + '     <div class="layui-form-item dataNameEdit">'
                                    + '         <div class="layui-input-inline">'
                                    + '             <input maxlength="25" autofocus="" type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input editNameInput">'
                                    + '          </div>'
                                    + '           <span class="icon confirm"></span>'
                                    + '           <span class="icon cancel"></span>'
                                    + '      </div>'
                                    + '   </td>'
                                    + '   <td>' + ((data.subjectName == null || data.subjectName == "" || data.subjectName == undefined) ? "" : data.subjectName) + '</td>'
                                    + '   <td>' + data.fileLength + '</td>'
                                    + '   <td>' + changeDate(data.createTime) + '</td>'
                                    + '   <td class="publicType">' + $.dataCenter.publicTypeHtml(data.auth) + '</td>'
                                    + '</tr>';
                            } else if ($(".authType").attr("data-auth") == "4") {
                                html += '<tr data-id=' + data.id + ' data-fileurl=' + data.fileUrl + ' data-extension=' + data.extension + '>'
                                    + '<td>'
                                    + '    <div class="schoolList">'+JSON.stringify(data.schoolList)+'</div>'
                                    + '    <input type="checkbox" name="" lay-skin="primary" title=' + index + '>'
                                    + '    <span class="iconMedia ' + iconName + '" data-fileurl=' + data.fileUrl + '></span>'
                                    + '    <div class="names" data-fileurl=' + data.fileUrl + '>'
                                    + '        <span class="name">' + data.name + '</span>.<span class="extension">' + data.extension + '</span>'
                                    + '    </div>'
                                    + '    <div class="controlButtons">'
                                    + '        <span class="icon save"></span>'
                                    + '        <span class="icon download"></span>'
                                    + '     </div>'
                                    + '   </td>'
                                    + '   <td>' + ((data.subjectName == null || data.subjectName == "" || data.subjectName == undefined) ? "" : data.subjectName) + '</td>'
                                    + '   <td>' + data.creator + '</td>'
                                    + '   <td>' + data.fileLength + '</td>'
                                    + '   <td>' + changeDate(data.createTime) + '</td>'
                                    + '</tr>';
                            } else if ($(".authType").attr("data-auth") == "2") {
                                html += '<tr data-id=' + data.id + ' data-fileurl=' + data.fileUrl + ' data-extension=' + data.extension + '>'
                                    + '<td>'
                                    + '    <div class="schoolList">'+JSON.stringify(data.schoolList)+'</div>'
                                    + '    <input type="checkbox" name="" lay-skin="primary" title=' + index + '>'
                                    + '    <span class="iconMedia ' + iconName + '" data-fileurl=' + data.fileUrl + '></span>'
                                    + '    <div class="names" data-fileurl=' + data.fileUrl + '>'
                                    + '        <span class="name">' + data.name + '</span>.<span class="extension">' + data.extension + '</span>'
                                    + '    </div>'
                                    + '    <div class="controlButtons">'
                                    + '        <span class="icon save"></span>'
                                    + '        <span class="icon download"></span>'
                                    + '     </div>'
                                    + '   </td>'
                                    + '   <td>' + ((data.subjectName == null || data.subjectName == "" || data.subjectName == undefined) ? "" : data.subjectName) + '</td>'
                                    + '   <td>' + data.schoolName + '</td>'
                                    + '   <td>' + data.creator + '</td>'
                                    + '   <td>' + data.fileLength + '</td>'
                                    + '   <td>' + changeDate(data.createTime) + '</td>'
                                    + '</tr>';
                            }
                        });
                    }else{
                        if($.dataCenter.pageIndex!="0"){
                            $.dataCenter.pageIndex=$.dataCenter.pageIndex-1;
                            $.dataCenter.dataList(true);
                            return;
                        }
                    }
                    $(".dataCenterList tbody").html(html);
                    $.dataCenter.initLayui();
                    $.dataCenter.initPage(result.totalElements);
                }, function () {
                });
                $.dataCenter.inputEmpty();
            },
            inputEmpty: function () {
                //引用完成后input全置为空
                $("input[type='checkbox']").attr("checked", false);
                $.each($("input[type='checkbox']"), function (i, inputs) {
                    $(inputs).attr("checked", false);
                    $.dataCenter.initLayui();
                });
            },
            /**
             * 组装icon className
             * @extension
             */
            iconName: function (extension) {
                switch (extension) {
                    case "mp3":
                    case "amr":
                    case "wav":
                        return "icon_voice";
                        break;
                    case "jpg":
                    case "jpeg":
                    case "png":
                    case "gif":
                        return "icon_picture";
                        break;
                    case "mp4":
                        return "icon_video";
                        break;
                    case "ppt":
                    case "pptx":
                        return "icon_ppt";
                        break;
                    case "doc":
                    case "docx":
                        return "icon_word";
                        break;
                    case "cwep":
                        return "icon_wait";
                        break;
                    case "cwp":
                        return "icon_courseware";
                        break;
                    default:
                        return "";
                        break;
                }
            },
            /**
             * 组装 publicTypeHtml
             * @extension
             */
            publicTypeHtml: function (auth) {
                switch (auth) {
                    case 1:
                        return "<span>个人</span>";
                        break;
                    case 2:
                        return "<span>公开</span>";
                        break;
                    case 3:
                        return "<span>提取码</span>";
                        break;
                    case 4:
                        return "<span>校本</span>";
                        break;
                    case 5:
                        return "<span>校本</span><span>公开</span>";
                        break;
                    case 6:
                        return "<span>校本</span><span>指定学校</span>";
                        break;
                    default:
                        return "";
                        break;

                }
            },
            /**
             * 初始化分页页码
             * @returns
             */
            initPage: function (total) {
                layui.use(['laypage'], function () {
                    var $ = layui.jquery, layer = layui.layer, laypage = layui.laypage;
                    laypage.render({
                        elem: 'pagination'
                        , count: total //数据总数，从服务端得到
                        , first: '首页'
                        , last: '尾页'
                        , layout: ['prev', 'page', 'next', 'skip', 'limit']
                        , curr: $.dataCenter.pageIndex + 1
                        , limit: $.dataCenter.pageSize
                        , skip: true
                        , theme: '#337ab7'
                        , jump: function (obj, first) {
                            $.dataCenter.pageIndex = obj.curr - 1;
                            $.dataCenter.pageSize = obj.limit;
                            //首次不执行
                            if (!first) {
                                $.dataCenter.dataList(true);
                            }
                        }
                    });
                });

            }
        }
    }();
    $.dataCenter.init();
})(jQuery);